/*
 * StringUtils.cpp
 *
 *  Created on: 03.12.2012
 *      Author: zheka
 */

#include "StringUtils.hpp"
#include <stdlib.h>
#include <sstream>

std::string StringUtils::trim(const std::string & s) {

	size_t left = 0;
	int right = s.length() - 1;

	while (left < s.length() && s[left] == ' ') {
		left++;
	}
	while (right >= 0 && s[right] == ' ') {
		right--;
	}

	std::string tmp = s.substr(left, (right - left + 1));
	std::string result;

	for(size_t i=0; i<tmp.length(); i++) {
		if(tmp[i] != '\r') {
			result += tmp[i];
		}
	}

	return result;

}

int StringUtils::toInteger(const std::string & s) {
	return atoi(s.c_str());
}

std::string StringUtils::toString(const int & value) {
	std::stringstream ss;
	ss << value;
	return ss.str();
}
